package com.itic.mobile.uc;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.applications.sys.msg.persistence.model.Msg;
import com.itic.appbase.applications.sys.msg.persistence.model.MsgExample;
import com.itic.appbase.applications.sys.msg.persistence.model.MsgExample.Criteria;
import com.itic.appbase.applications.sys.msg.service.MsgService;
import com.itic.appbase.applications.sys.tixianlog.persistence.model.TixianLog;
import com.itic.appbase.applications.sys.tixianlog.persistence.model.TixianLogExample;
import com.itic.appbase.applications.sys.tixianlog.service.TixianLogService;
import com.itic.appbase.applications.sys.user.persistence.model.SysUser;
import com.itic.appbase.applications.sys.useraccount.persistence.model.UserAccount;
import com.itic.appbase.applications.sys.useraccount.persistence.model.UserAccountVo;
import com.itic.appbase.applications.sys.useraccount.service.UserAccountService;
import com.itic.appbase.framework.annotation.CheckLogin;
import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.appbase.framework.utils.ValueHelper;
import com.itic.mobile.base.BaseMobile;
import com.itic.system.market.product.persistence.model.Product;
import com.itic.system.market.productcollect.persistence.model.ProductCollect;
import com.itic.system.market.productcollect.persistence.model.ProductCollectExample;
import com.itic.system.market.productcollect.persistence.model.ProductCollectVo;
import com.itic.system.market.productcollect.service.ProductCollectService;
import com.itic.system.market.viptype.persistence.model.VipType;
import com.itic.system.market.viptype.persistence.model.VipTypeExample;
import com.itic.system.market.viptype.service.VipTypeService;
import com.itic.system.order.orderproduct.persistence.model.OrderProduct;
import com.itic.system.order.orderproduct.persistence.model.OrderProductExample;
import com.itic.system.order.orderproduct.service.OrderProductService;

@Controller
@RequestMapping(value = "/mobile/uc")
public class UcMobile extends BaseMobile {
	
	private static String VIP_CODE_TYPE="T_DM_SYS_USER_VIP_TYPE";

	private static String VIP="vip";
	@Autowired
	private MsgService msgService;
	
	@Autowired
	private ProductCollectService productCollectService;
	
	@Autowired
	private OrderProductService orderProductService;
	
	@Autowired
	private UserAccountService userAccountService;
	
	@Autowired
	private TixianLogService tixianLogService;
	
	@Autowired
	private VipTypeService vipTypeService;
	
	
	protected static String[] ignoreMsgProperties = new String[] { "createUser", "isEffective", "updateTime",
			"note", "orgCode", "reorder", "isOpen" };
	
	protected static String[] ignoreVipProperties = new String[] { "id", "createUser", "isEffective", "updateTime",
			"note", "createTime", "orgCode", "reorder", "parentId","type","orderNo" };
	
	protected static String[] ignoreVipTypeProperties = new String[] {"createUser", "isEffective", "updateTime",
			"note", "createTime", "orgCode", "reorder" };
	

	protected static String[] ignoreTixianLogProperties = new String[] { "id", "createUser", "isEffective",
			"note", "createTime", "orgCode", "reorder", "parentId","type","orderNo","userId","userName","userAccountId" };


	/**
	 * 商品列表
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/index")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> index(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			Map<String, Object> dataMap = new HashMap<String, Object>();
			SysUser user = getRequestUser(request);
			dataMap.put("headImg", user.getHeadImg()==null?getDefaultHeadImg():user.getHeadImg());
			dataMap.put("userName", user.getUsername()==null?"您还没有名称":user.getUsername());
			dataMap.put("isVip", user.getIsVip()==null?"user":user.getIsVip());
			dataMap.put("msgTips", user.getMsgTips()==null?"0":user.getMsgTips());
			resultMap.put(DATA, dataMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "index", e.toString(), "进入个人中心", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}

	/**
	 * 编辑用户资料
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/edit")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> edit(HttpServletRequest request, HttpServletResponse response, String headImg,String userName ) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			SysUser user = getRequestUser(request);
			if( StringHelper.isNotBlank(headImg) ){
				user.setHeadImg(headImg);
			}
			if( StringHelper.isNotBlank(userName) ){
				user.setUsername(userName);
			}
			sysUserService.edit(user);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "edit", e.toString(), "编辑用户资料", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}

	/**
	 * 消息列表
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/msgs")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> msgs(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			
			Map<String, Object> dataMap = new HashMap<String, Object>();
			MsgExample example = new MsgExample();
			example.setOrderByClause("CREATE_TIME DESC");
			Criteria criteria = example.createCriteria();
			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
			criteria.andIsOpenEqualTo("open");
			this.handlePageQueryDefault(request, example);// 分页
			int count = msgService.count(example);// 总条数
			List<Msg> list = msgService.list(example);// 数据list

			dataMap.put("total", count);
			dataMap.put("isMore", isMore(request, count));
			dataMap.put("list", ValueHelper.tranList2MapList(list, ignoreMsgProperties));
			resultMap.put(DATA, dataMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
			
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "msgs", e.toString(), "消息列表", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	/**
	 * 用户读取消息
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/readMsg")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> readMsg(HttpServletRequest request, HttpServletResponse response,String msgId) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			
			if( StringHelper.isNotBlank(msgId) ){
				Msg msg = msgService.get(msgId);
				if( null != msg ){
					Map<String, Object> dataMap = new HashMap<String, Object>();
					SysUser user = getRequestUser(request);
					msgService.readMsg(user,msg);
					dataMap.put("title", msg.getTitle());
					dataMap.put("content", msg.getContent());
					dataMap.put("image", msg.getImage());
					resultMap.put(DATA, dataMap);
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}else{
					errorCode = MSG_NULL_ERROR_CODE;
					errorMsg = MSG_NULL_ERROR_MSG;//未找到消息
				}
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "readMsg", e.toString(), "用户读取消息", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	/**
	 * 用户收藏历史
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/collecteds")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> collecteds(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			SysUser user = getRequestUser(request);
			
			Map<String, Object> dataMap = new HashMap<String, Object>();
			ProductCollectExample example = new ProductCollectExample();
			example.setOrderByClause("CREATE_TIME DESC");
			com.itic.system.market.productcollect.persistence.model.ProductCollectExample.Criteria criteria = example.createCriteria();
			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
			criteria.andUserIdEqualTo(user.getId());
			this.handlePageQueryDefault(request, example);// 分页
			int count = productCollectService.count(example);// 总条数
			List<ProductCollect> listTemp = productCollectService.list(example);// 数据list
			List<ProductCollectVo> list = new ArrayList<ProductCollectVo>();
			if( !listTemp.isEmpty() ){
				for( ProductCollect temp: listTemp ){
					Product product = productService.get(temp.getProductId());
					if( null != product ){
						ProductCollectVo vo = new ProductCollectVo();
						vo.setId(product.getId());
						vo.setProductImage(product.getProductImage());
						vo.setProductName(product.getProductName());
						vo.setPlayCounts(product.getPlayCounts());
						list.add(vo);
					}
				}
			}
			dataMap.put("total", count);
			dataMap.put("isMore", isMore(request, count));
			dataMap.put("list", list);
			resultMap.put(DATA, dataMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
			
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "collecteds", e.toString(), "用户收藏列表", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	/**
	 * 用户收藏历史
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/addCollecteds")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> addCollecteds(HttpServletRequest request, HttpServletResponse response,String productId) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if( StringHelper.isNotBlank(productId) ){
				Product product = productService.get(productId);
				if( null != product ){
					SysUser user = getRequestUser(request);
					ProductCollectExample example = new ProductCollectExample();
					com.itic.system.market.productcollect.persistence.model.ProductCollectExample.Criteria criteria = example.createCriteria();
					criteria.andIsEffectiveEqualTo(DBConst.TRUE);
					criteria.andUserIdEqualTo(user.getId());
					criteria.andProductIdEqualTo(productId);
					List<ProductCollect> list = productCollectService.list(example);
					if( list.isEmpty() ){
						ProductCollect collect = new ProductCollect();
						collect.setUserId(user.getId());
						collect.setProductId(productId);
						collect.setProductImage(product.getProductImage());
						collect.setProductName(product.getProductName());
						collect.setUserName(user.getUsername());
						productCollectService.add(collect);
					}
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}else{
					errorCode = PRODUCT_EMPTY_ERROR_CODE;
					errorMsg = PRODUCT_EMPTY_ERROR_MSG;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "collecteds", e.toString(), "用户收藏列表", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	/**
	 * 用户收藏历史
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/cancelCollecteds")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> cancelCollecteds(HttpServletRequest request, HttpServletResponse response,String productId) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if( StringHelper.isNotBlank(productId) ){
				SysUser user = getRequestUser(request);
				ProductCollectExample example = new ProductCollectExample();
				com.itic.system.market.productcollect.persistence.model.ProductCollectExample.Criteria criteria = example.createCriteria();
				criteria.andIsEffectiveEqualTo(DBConst.TRUE);
				criteria.andUserIdEqualTo(user.getId());
				criteria.andProductIdEqualTo(productId);
				productCollectService.deleteByExample(new ProductCollect(), example);
				errorCode = SUCCESS_ERROR_CODE;
				errorMsg = SUCCESS_ERROR_MSG;
			}
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "collecteds", e.toString(), "用户收藏列表", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	/**
	 * 商品购买历史 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/payHistory")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> payHistory(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			
			Map<String, Object> dataMap = new HashMap<String, Object>();
			SysUser user = getRequestUser(request);
			
			OrderProductExample example = new OrderProductExample();
			example.setOrderByClause("CREATE_TIME DESC");
			com.itic.system.order.orderproduct.persistence.model.OrderProductExample.Criteria criteria = example.createCriteria();
			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
			criteria.andUserIdEqualTo(user.getId());
			this.handlePageQueryDefault(request, example);// 分页
			int count = orderProductService.count(example);// 总条数
			List<OrderProduct> listTemp = orderProductService.list(example);// 数据list
			List<ProductCollectVo> list = new ArrayList<ProductCollectVo>();
			if( !listTemp.isEmpty() ){
				for( OrderProduct temp: listTemp ){
					Product product = productService.get(temp.getProductId());
					if( null != product ){
						ProductCollectVo vo = new ProductCollectVo();
						vo.setId(product.getId());
						vo.setProductImage(product.getProductImage());
						vo.setProductName(product.getProductName());
						vo.setPlayCounts(product.getPlayCounts());
						list.add(vo);
					}
				}
			}
			dataMap.put("total", count);
			dataMap.put("isMore", isMore(request, count));
			dataMap.put("list", list);
			resultMap.put(DATA, dataMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
			
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "payHistory", e.toString(), "商品购买历史 ", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	/**
	 * 购买会员类型
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/vipTypes")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> vipTypes(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			Map<String, Object> dataMap = new HashMap<String, Object>();
			SysUser user = getRequestUser(request);
			/*
			CodeDetailVo vo = new CodeDetailVo();
			vo.setType(VIP_CODE_TYPE);
		    List<CodeDetail> list = outCommonService.getCodeDetail(vo);*/
		    VipTypeExample example = new VipTypeExample();
		    com.itic.system.market.viptype.persistence.model.VipTypeExample.Criteria criteria = example.createCriteria();
		    criteria.andIsEffectiveEqualTo(DBConst.TRUE);
		    List<VipType> list = vipTypeService.list(example);
			
		    if( VIP.equals(user.getIsVip()) && user.getVipExpiredTime().getTime() >= new Date().getTime() ){
		    	dataMap.put("vipExpiredTime", user.getVipExpiredTime() );
		    }else{
		    	dataMap.put("vipExpiredTime","已到期");
		    }
			dataMap.put("userName", user.getUsername());
			dataMap.put("headImg", user.getHeadImg()==null?getDefaultImage():user.getHeadImg());
			dataMap.put("vipList", ValueHelper.tranList2MapList(list, ignoreVipTypeProperties));
			resultMap.put(DATA, dataMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
			
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "payHistory", e.toString(), "商品购买历史 ", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	/**
	 * 获得用户余额
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/initTianxian")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> initTianxian(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			Map<String, Object> dataMap = new HashMap<String, Object>();
			SysUser user = getRequestUser(request);
			dataMap.put("money",  user.getMoney()==null?0.00:user.getMoney());
			List<UserAccount> list = sysUserService.getUserAccount(user);
			UserAccountVo accountVo = new UserAccountVo();
			if( !list.isEmpty() ){
				 UserAccount userAccount = list.get(0);
				 accountVo.setAccountId(userAccount.getId());
				 accountVo.setAccountName(userAccount.getAccountName());
				 accountVo.setAccountNum(userAccount.getAccountNum());
				 accountVo.setAccountType(userAccount.getAccountType());
			}
			dataMap.put("account", accountVo);
			resultMap.put(DATA,dataMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
			
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "initTianxian", e.toString(), "用户准备提现 ", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	/**
	 * 用户添加账号
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/accountAddOrEdit")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> accountAddOrEdit(HttpServletRequest request, HttpServletResponse response,String accountType,String accountName,String accountNum, String accountId ) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			if( StringHelper.isNotBlank(accountName) && StringHelper.isNotBlank(accountNum) && StringHelper.isNotBlank(accountType) ){
				SysUser user = getRequestUser(request);
				UserAccount userAccount = new UserAccount();
				if( StringHelper.isNotBlank(accountId) ){
					UserAccount accountOld = userAccountService.get(accountId);
					if( null != accountOld ){
						accountOld.setAccountName(accountName);
						accountOld.setAccountNum(accountNum);
						accountOld.setAccountType(accountType);
						userAccountService.edit(accountOld);
						errorCode = SUCCESS_ERROR_CODE;
						errorMsg = SUCCESS_ERROR_MSG;
					}else{
						userAccount.setUserId(user.getId());
						userAccount.setUserName(user.getRealname());
						userAccount.setAccountType(accountType);
						userAccount.setAccountName(accountName);
						userAccount.setAccountNum(accountNum);
						userAccountService.add(userAccount);
						errorCode = SUCCESS_ERROR_CODE;
						errorMsg = SUCCESS_ERROR_MSG;
					}
				}else{
					userAccount.setUserId(user.getId());
					userAccount.setUserName(user.getRealname());
					userAccount.setAccountType(accountType);
					userAccount.setAccountName(accountName);
					userAccount.setAccountNum(accountNum);
					userAccountService.add(userAccount);
					errorCode = SUCCESS_ERROR_CODE;
					errorMsg = SUCCESS_ERROR_MSG;
				}
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "accountAddOrEdit", e.toString(), "用户添加账号", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	
	
	/**
	 * 用户提现
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/tixianSubmit")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> tixianSubmit(HttpServletRequest request, HttpServletResponse response,String money,String accountId ) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			SysUser user = getRequestUser(request);
			if( StringHelper.isNotBlank(money) && StringHelper.isNotBlank(accountId) ){
				if(  user.getMoney()>=Double.parseDouble(money) ){
					UserAccount account = userAccountService.get(accountId);
					if( null != account ){
						sysUserService.tixianSubmit(user,money,account);
						errorCode = SUCCESS_ERROR_CODE;
						errorMsg = SUCCESS_ERROR_MSG;
					}else{
						errorCode = ACCOUNT_ID_ERROR_CODE;
						errorMsg = ACCOUNT_ID_ERROR_MSG;
					}
				}else{
					errorCode = LESS_MONEY_ERROR_CODE;
					errorMsg = LESS_MONEY_ERROR_MSG;
				}
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "tixian", e.toString(), "用户提现", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}
	
	

	/**
	 * 用户提现记录 
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/tixianList")
	@ResponseBody
	@CheckLogin
	public Map<String, Object> tixianList(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String errorCode = PARAM_ERROR_CODE;
		String errorMsg = PARAM_ERROR_MSG;
		try {
			
			Map<String, Object> dataMap = new HashMap<String, Object>();
			SysUser user = getRequestUser(request);
			
			TixianLogExample example = new TixianLogExample();
			example.setOrderByClause("CREATE_TIME DESC");
			com.itic.appbase.applications.sys.tixianlog.persistence.model.TixianLogExample.Criteria criteria = example.createCriteria();
			criteria.andIsEffectiveEqualTo(DBConst.TRUE);
			criteria.andUserIdEqualTo(user.getId());
			this.handlePageQueryDefault(request, example);// 分页
			int count = tixianLogService.count(example);// 总条数
			List<TixianLog> list = tixianLogService.list(example);// 数据list
			dataMap.put("total", count);
			dataMap.put("isMore", isMore(request, count));
			dataMap.put("list", ValueHelper.tranList2MapList(list, ignoreTixianLogProperties));
			resultMap.put(DATA, dataMap);
			errorCode = SUCCESS_ERROR_CODE;
			errorMsg = SUCCESS_ERROR_MSG;
			
		} catch (Exception e) {
			e.printStackTrace();
			errorCode = SERVER_ERROR_CODE;
			errorMsg = SERVER_ERROR_MSG;
			logException("UcMobile", "tixianList", e.toString(), "用户提现记录 ", e);
		}
		resultMap.put(CODE, errorCode);
		resultMap.put(MSG, errorMsg);
		isCrrossDomain(response);
		return resultMap;
	}

	/**
	 * 系统默认图片
	 * @return
	 */
	private String getDefaultImage() {
		return "http://www.uhuijia.com.cn/huifa/default.jpg";
	}
	
	
	
}